﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;

namespace Core
{
    public class Logger
    {
        private static string path;
        private static Logger instance = null;

        public static string PathToLog
        {
            get { return Logger.path; }
        }

        protected Logger()
        {

            
            path = System.Configuration.ConfigurationManager.AppSettings["LogLocation"].ToString();//
            //m_path =  "log.txt";// it's not good idea
        }

        public static Logger Instance()
        {
            if (instance == null)
            {
                instance = new Logger();
            }
            return instance;
        }

        public void Record(string msg)
        {
            using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write))
            {
                AddText(fs, msg +" @ "+ DateTime.Now.ToString());
            }
        }

        private void AddText(FileStream fs, string value)
        {
            byte[] info = new UTF8Encoding(true).GetBytes("\r\n"+value);
            fs.Write(info, 0, info.Length);
        }

    }
}
